package Behavioral_design_pattern.Iterator_Pattern;

public class SkyworthTelevision implements Television {
    private Object[]  obj = {"湖南卫视","北京卫视","上海卫视"};
    public TVIterator createIterator() {
        return new SkyworthIterator();
    }

    // 内部类，实现抽象迭代器
    private class SkyworthIterator implements TVIterator {

        private int currentIndex = 0;
        @Override
        public void setChannel(int i) {
            currentIndex = i;
        }

        @Override
        public Object currentChannel() {
            return obj[currentIndex];
        }

        @Override
        public void next() {
            if(currentIndex<obj.length){
                currentIndex++;
            }
        }

        @Override
        public void previous() {
            if(currentIndex>0){
                currentIndex--;
            }
        }

        @Override
        public boolean isLast() {
            return currentIndex==obj.length;
        }

        @Override
        public boolean isFirst() {
            return currentIndex==0;
        }
    }
}
